#include "../tools.h"


class Solution {
public:
    int res = 0, tsum;
    void trace(TreeNode* root, int cursum){
        if(root == nullptr) return;

        cursum += root->val;
        cout << root->val << " " << cursum << endl;
        if(cursum == tsum) ++res;

        if(root->left != nullptr) trace(root->left, cursum);
        if(root->right != nullptr) trace(root->right, cursum);
    }
    int pathSum(TreeNode* root, int targetSum) {
        if(root == nullptr) return 0;

        tsum = targetSum;
        queue<TreeNode*> q;
        q.push(root);
        while(!q.empty()){
            TreeNode* curnode = q.front();
            q.pop();
            cout << curnode->val << "--------------" << endl;
            trace(curnode, 0);

            if(curnode->left != nullptr) q.push(curnode->left);
            if(curnode->right != nullptr) q.push(curnode->right);
        }
        return res;
    }
};

int main(int argc, char const *argv[])
{
    Solution sol;

    vector<int> vec = {22};
    TreeNode* root = create_tree(vec);
    show(root);
    int targetSum = 22;
    
    cout << sol.pathSum(root, targetSum);




    return 0;
}
